#!/usr/bin/env ruby

#require 'bundler/setup'
require 'thor'
require 'v1gittools'
include V1gittools


# for dev purposes
Dir.chdir(ENV['v1git_cwd']) if ENV['v1git_cwd']

class V1git < Thor
  option :title, :type => :string, :banner => 'v1|git', :aliases => :t, desc: '"git" or "versionone" title, defaults to v1 title [v1,git]'
  desc 'changelog start end', 'Generates a changelog of merged PRs with VersionOne tags'
  def changelog(start_snapshot, end_snapshot)
    tool = ChangeLogTool.new options
    tool.generate_changelog(start_snapshot,end_snapshot)
  end

  desc 'develop v1_story_id [branch_name]', 'Move a v1 story into "in-progress" and start a new branch off of develop. If branch is not specified, defaults to story id name'
  def develop(v1_story_id, branch_name = nil)
    tool = DevelopStoryTool.new
    tool.develop(v1_story_id,branch_name)
  end

  desc 'qa', 'Moves the current story/branch to "In-Test" and creates a PR in github'
  def qa
    tool = QATool.new
    tool.qa
  end


  desc 'init', 'Initializes repo settings for v1git'
  def init
    V1gittools::generate_repo_config V1gittools::repo_config_path
    V1gittools::initialize_github

    puts "Running validations... (if any of these fail, run '#{$0} validate' after correcting the issue.)"
    V1gittools::validate_config
  end

  desc 'validate', 'Validates config and connections and verifies if everything works.'
  def validate
    V1gittools::validate_config

    puts "All validations pass! You're ready to run v1git on your project!"
  end
end



V1git.start(ARGV)
